﻿using System;
using System.ComponentModel.DataAnnotations;

namespace Web.Models.His
{
    public class AddUserValidate
    {
        /// <summary>
        /// 业务编号
        /// </summary>
        public string TranCode { get; set; } = "0003";

        /// <summary>
        /// 社保卡号
        /// </summary>
        public string MediCardNo { get; set; } = "";

        /// <summary>
        /// 姓名
        /// </summary>
        [Required]
        public string PatientName { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public string Sex
        {
            get
            {
                try
                {
                    if(IDCardNo.Length == 15)
                    {
                        if (int.Parse(IDCardNo.Substring(13, 1)) % 2 == 0)
                        {
                            return "2";
                        }

                        return "1";
                    }
                    else
                    {
                        if (int.Parse(IDCardNo.Substring(16, 1)) % 2 == 0)
                        {
                            return "2";
                        }

                        return "1";
                    }
                }
                catch (Exception)
                {
                    return "3";
                }
            }
        }

        /// <summary>
        /// 出生日期
        /// </summary>
        public string Birthday
        {
            get
            {
                if(IDCardNo.Length == 15)
                {
                    var y = int.Parse($"19{IDCardNo.Substring(6, 2)}");
                    var m = int.Parse(IDCardNo.Substring(8, 2));
                    var d = int.Parse(IDCardNo.Substring(10, 2));
                    return new DateTime(y, m, d).ToString("yyyy-MM-dd");
                }
                else
                {
                    var y = int.Parse(IDCardNo.Substring(6, 4));
                    var m = int.Parse(IDCardNo.Substring(10, 2));
                    var d = int.Parse(IDCardNo.Substring(12, 2));
                    return new DateTime(y, m, d).ToString("yyyy-MM-dd");
                }

            }
        }

        /// <summary>
        /// 年龄
        /// </summary>
        public string Age
        {
            get
            {
                if (IDCardNo.Length == 15)
                {
                    var y = int.Parse($"19{IDCardNo.Substring(6, 2)}");
                    var m = int.Parse(IDCardNo.Substring(8, 2));
                    var d = int.Parse(IDCardNo.Substring(10, 2));
                    return (DateTime.Now.Year - new DateTime(y, m, d).Year).ToString();
                }
                else
                {
                    var y = int.Parse(IDCardNo.Substring(6, 4));
                    var m = int.Parse(IDCardNo.Substring(10, 2));
                    var d = int.Parse(IDCardNo.Substring(12, 2));
                    return (DateTime.Now.Year - new DateTime(y, m, d).Year).ToString();
                }

            }
        }

        /// <summary>
        /// 身份证号码
        /// </summary>
        [Required]
        public string IDCardNo { get; set; }

        /// <summary>
        /// Uid
        /// </summary>
        public string Uid { get; set; } = "";

        /// <summary>
        /// 地址
        /// </summary>
        public string Address { get; set; } = "";

        /// <summary>
        /// 电话号码
        /// </summary>
        [Required]
        public string Tel { get; set; }

        /// <summary>
        /// 充值金额
        /// </summary>
        public string Amt { get; set; } = "0";

        /// <summary>
        /// 操作日期
        /// </summary>
        public string ActDate { get; set; } = DateTime.Now.ToString("yyyy-MM-dd");

        /// <summary>
        /// 操作时间
        /// </summary>
        public string ActTime { get; set; } = DateTime.Now.ToString("HH:mm");

        /// <summary>
        /// 流水号
        /// </summary>
        public string FlowNo { get; set; } = "";

        /// <summary>
        /// 11:现金, 12:POS, 17:微信, 18:支付宝, 191:住院收费退款
        /// </summary>
        [Required]
        public string TranType { get; set; }

        /// <summary>
        /// 备注
        /// </summary>
        public string Notes { get; set; } = "";

        /// <summary>
        /// 民族
        /// </summary>
        public string National { get; set; } = "";

        /// <summary>
        /// 
        /// </summary>
        public string IsParent { get; set; } = "1";

        /// <summary>
        /// 张三
        /// </summary>
        public string LxrXm { get; set; } = "";

        /// <summary>
        /// 
        /// </summary>
        public string LxrDh { get; set; } = "";

        /// <summary>
        /// 
        /// </summary>
        public string LxrIDCardNo { get; set; } = "";

        /// <summary>
        /// 自助机ID
        /// </summary>
        [Required]
        public string UserId { get; set; }

        /// <summary>
        /// MAC地址
        /// </summary>
        [Required]
        public string MacAddress { get; set; }
    }
}
